<?php
	$this->widget('zii.widgets.grid.CGridView',array(
			'id'=>"cargo-grid",
			'dataProvider'=>$model->inPacking_list(),
			'template'=>"{items}\n{pager}",
			'columns'=>array(
				array(
					'value'=>'$data->allPackage()',
					'header'=>'Package marking',
					'type'=>'text',
				),
				array(
					'value'=>'$data->in_date',
					'header'=>'Date received',
					'type'=>'date',
				),
				array(
					'class'=>'CLinkColumn',
					'header'=>'Marking',
					'labelExpression'=>'$data->marking',
					'urlExpression'=>'CHtml::normalizeUrl(array("cargo/view","id"=>$data->id))'
				),
				array(
					'value'=>'$data->consignee->cname',
					'header'=>'Consignee',
				),
				array(
				'header'=>'Dimension',
				'value'=>'$data->dimension->qty.$data->dimension->qty_type." / ".$data->dimension->wt.$data->dimension->wt_type." / ".$data->dimension->m3',
				),
				array(
					'class'=>'CButtonColumn',
					'template'=>'{update}{delete}',
					'updateButtonUrl'=>'($data->package==NULL)?CHtml::normalizeUrl(array("packing_list_packages_cargo/create","cargo_id"=>$data->id)):CHtml::normalizeUrl(array("/packing_list_packages_cargo/update","cargo_id"=>$data->id))',
					'deleteButtonUrl'=>'CHtml::normalizeUrl(array("cargo/removefrompacking","id"=>$data->id))',
					'updateButtonOptions'=>array('id'=>'grid_updatePackageCargo'),
				),
			),
		));
?>
<?php
$validate = (Yii::app()->request->enableCsrfValidation)?",".Yii::app()->request->csrfTokenName.":'".yii::app()->request->csrfToken."'":'';
$script =<<<EOD
$('a#addcargo').click(function(){
	var dialogButton = {
		Add:function(){
			var dialog = $(this);
			$.packing_list_packages_cargo = {
				afterSubmit:function(data){
					$(dialog).dialog('close');
				}
			};
			$(this).find('[type=submit]').click();			
		}
	};
	$.simplelogdialog({url:$(this).attr('href')},{width:400},dialogButton);
	return false;
});
EOD;
$cs = Yii::app()->getClientScript();
$cs->registerScript('packing_list_packages#gridcargo',$script);
?>